package com.gitee.feizns.utils.bean;

import java.util.Arrays;

/**
 * @author feizns
 * @since 2019/4/3
 */
public abstract class BeanUtils {

    /**
     * 映射为指定类型
     * @param source
     * @param clz
     * @param <T>
     * @return
     */
    public static <T> T copyFrom(Object source, Class<T> clz) {
        T result = newInstance(clz);
        org.springframework.beans.BeanUtils.copyProperties(source, result);
        return result;
    }

    /**
     * 创建对象
     * @param clz
     * @param <T>
     * @return
     */
    public static <T> T newInstance(Class<T> clz) {
        try {
            return clz.newInstance();
        } catch ( ReflectiveOperationException e ) {
            throw new RuntimeException(e);
        }
    }

    private static final <T> Class<T>[] getClasses(Object... objects) {
        return Arrays.stream(objects).map(Object::getClass).toArray(Class[]::new);
    }

}
